package com.example.utils;

import java.sql.*;

/**
 * 数据库连接工具
 */
public class JDBCUtil {

    public static Connection connection() throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/today_news?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
        Connection connection = DriverManager.getConnection(url, "root", "root");
        return connection;
    }

    /**
     * 关闭数据库连接
     *
     * @param ps
     * @param cn
     */
    public static void closeConn(PreparedStatement ps, Connection cn) throws SQLException {
        if (ps != null) {
            ps.close();
        }
        if (cn != null) {
            cn.close();
        }
    }

}
